<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/1/2
 * Time: 10:09
 */
namespace app\admin\controller;
use think\Db;
class Num extends Base {
    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::table('up_num_config')->alias('a')

                ->count();//计算总页面
            $list = Db::table('up_num_config')
                ->alias ('a')
                ->page($page, $limit)
                ->select();
            foreach ($list as $key=>&$vo){
                if($vo['status']==1){
                 $vo['num_name'] ='条';
                }else{
                    $vo['num_name'] = '月';
                }
            }
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$list]);
        }
        return $this->fetch();
    }


    public function update(){
        $id = input('param.id');
        $num = input('param.value');
        $data['num'] = $num;
        $res = Db::table('up_num_config')->where('id',$id)->update($data);
        if($res){
            return ['code' => 200, 'data' => '', 'msg' => '更新字段成功'];
        }else{
            return ['code' => 100, 'data' => '', 'msg' => '更新字段失败'];

        }

    }
}